<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Login Page</title>
		<link rel="stylesheet" href="component/pear/css/pear.css" />
		<link rel="stylesheet" href="admin/css/other/login.css" />
	</head>
    <!-- 代 码 结 构 -->
	<body style="background-size: cover;background-color:lightskyblue;">
		<form  class="layui-form" action="javascript:void(0);">
			<div class="layui-form-item">
				<div class="title">客户关系管理系统</div>
			</div>
			<div class="layui-form-item">
				<input placeholder="账 户 " name="username" hover class="layui-input"  />
			</div>
			<div class="layui-form-item">
				<input placeholder="密 码 " name="password" type="password" hover class="layui-input"  />
			</div>

			<div class="layui-form-item">
				<button class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
					登 陆
				</button>
			</div>
		</form>
		<!-- 资 源 引 入 -->
		<script src="component/layui/layui.js"></script>
		<script src="component/pear/pear.js"></script>
		<script>
			layui.use(['form', 'element', 'jquery', 'button', 'popup'], function() {
				var form = layui.form;
				var element = layui.element;
				var button = layui.button;
				var popup = layui.popup;
				var $ = layui.jquery;

                // 登 录 提 交
				form.on('submit(login)', function(data) {
					console.log(data);
					//异步请求
					$.ajax({
						url:'http://localhost:8181/Manager_war/empServlet/login',//后端控制器地址(Servlet)
						data:data.field,// username, password
						type:'post',// get
						dataType:"json",//"txt"
						//后端返回的类型应该是一个  json格式的数据
						// ,如果不写返回类型 默认后端返回的是 一个txt
						success:function(result){
							console.log(result);
							//判断 状态码
							if(result.code==0){
								layer.msg(result.msg,{icon:1,time:1000},function(){
									//跳转到首页
									location.href = "index.html"
									//存储token到Storage  只能单个存储  一个数据   data是一个json数据
									localStorage.setItem("name",result.data.emp_loginid);
								});
							}else{
								layer.msg(result.msg,{icon:2,time:1000});
							}
						}
					})

				});




			})
		</script>
	</body>
</html>
